import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '商户管理', icon: 'dashboard' }
    }]
  },

  {
    path: '/form',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: '店铺管理', icon: 'form' }
      }
    ]
  },
  
  {
    path: '/visualization',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Visualization',
        component: () => import('@/views/visualization/index'),
        meta: { title: '可视化平台', icon: 'form' }
      }
    ]
  },
  
  {
    path: '/cluemanagement',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Cluemanagement',
        component: () => import('@/views/cluemanagement/index'),
        meta: { title: '线索管理', icon: 'form' }
      }
    ]
  },
  
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    meta: { title: '物料管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: { title: '教育课程', icon: 'table' }
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/tree/index'),
        meta: { title: '教育评论', icon: 'tree' }
      },
      {
        path: 'shop',
        name: 'Shop',
        component: () => import('@/views/shop/index'),
        meta: { title: '店铺物料', icon: 'tree' }
      },
      {
        path: 'top1',
        name: 'TOP1',
        component: () => import('@/views/top1/index'),
        meta: { title: 'TOP1攻略', icon: 'tree' }
      },
      {
        path: 'boutique',
        name: 'Boutique',
        component: () => import('@/views/boutique/index'),
        meta: { title: '精品攻略', icon: 'tree' }
      },
      {
        path: 'brand',
        name: 'Brand',
        component: () => import('@/views/brand/index'),
        meta: { title: '品牌介绍', icon: 'tree' }
      },
      {
        path: 'teacher',
        name: 'Teacher',
        component: () => import('@/views/teacher/index'),
        meta: { title: '老师介绍', icon: 'tree' }
      },
      {
        path: 'curriculumSEO',
        name: 'CurriculumSEO',
        component: () => import('@/views/curriculumSEO/index'),
        meta: { title: '课程SEO关键词', icon: 'tree' }
      },
      {
        path: 'massiveRaiders',
        name: 'MassiveRaiders',
        component: () => import('@/views/massiveRaiders/index'),
        meta: { title: '海量攻略', icon: 'tree' }
      },
      {
        path: 'formcomponent',
        name: 'Formcomponent',
        component: () => import('@/views/formcomponent/index'),
        meta: { title: '表单组件', icon: 'tree' }
      },
      {
        path: 'telephonecomponents',
        name: 'Telephonecomponents',
        component: () => import('@/views/telephonecomponents/index'),
        meta: { title: '电话组件', icon: 'tree' }
      },
      {
        path: 'imassembly',
        name: 'IMassembly',
        component: () => import('@/views/imassembly/index'),
        meta: { title: 'IM组件', icon: 'tree' }
      }
    ]
  },

  {
    path: '/relationship',
    component: Layout,
    redirect: '/relationship/release',
    name: 'Relationship',
    meta: { title: '物料关系', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'release',
        name: 'Release',
        component: () => import('@/views/release/index'),
        meta: { title: '物料关系发布', icon: 'table' }
      },
      {
        path: 'relationshiplist',
        name: 'RelationshipList',
        component: () => import('@/views/relationshiplist/index'),
        meta: { title: '物料关系列表', icon: 'tree' }
      }
    ]
  },

  {
    path: '/finance',
    component: Layout,
    redirect: '/finance/rechargerecord',
    name: 'Finance',
    meta: { title: '财务管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'rechargerecord',
        name: 'Rechargerecord',
        component: () => import('@/views/rechargerecord/index'),
        meta: { title: '充值列表', icon: 'table' }
      },
      {
        path: 'orderlist',
        name: 'Orderlist',
        component: () => import('@/views/orderlist/index'),
        meta: { title: '订单列表', icon: 'tree' }
      },
      {
        path: 'generationbuy',
        name: 'Generationbuy',
        component: () => import('@/views/generationbuy/index'),
        meta: { title: '代买认证包订单', icon: 'tree' }
      }
    ]
  },

{
    path: '/draftmanagement',
    component: Layout,
    redirect: '/draftmanagement/storelist',
    name: 'Draftmanagement',
    meta: { title: '草稿管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'storelist',
        name: 'Storelist',
        component: () => import('@/views/storelist/index'),
        meta: { title: '店铺列表', icon: 'table' }
      },
      {
        path: 'materiallist',
        name: 'Materiallist',
        component: () => import('@/views/materiallist/index'),
        meta: { title: '物料列表', icon: 'tree' }
      }
    ]
  },

  {
    path: '/jurisdiction',
    component: Layout,
    redirect: '/jurisdiction/usermanagement',
    name: 'Jurisdiction',
    meta: { title: '权限', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'usermanagement',
        name: 'Usermanagement',
        component: () => import('@/views/usermanagement/index'),
        meta: { title: '用户管理', icon: 'table' }
      },
      {
        path: 'rolemanagement',
        name: 'Rolemanagement',
        component: () => import('@/views/rolemanagement/index'),
        meta: { title: '角色管理', icon: 'tree' }
      },
      {
        path: 'menumanagement',
        name: 'Menumanagement',
        component: () => import('@/views/menumanagement/index'),
        meta: { title: '菜单管理', icon: 'tree' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
